﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：机构管理
 */

var acceptClick;

var bootstrap = function ($, learun) {
    "use strict";
    var selectedRow = config.getParent(learun).selectedRow;
    var page = {
        init: function () {
            page.bind();
            page.initData();
            if (!!selectedRow) {
                $('#code').attr('readonly', 'readonly');
            }
        },
        bind: function () {
            $('#admin1Userid').lrformselect({
                layerUrl: config.webportal_server + 'pages/system/user/selectForm.html?access_token=' + config.getToken().access_token,
                layerUrlW: 800,
                layerUrlH: 520,
                dataUrl: config.base_server() + 'users/getName?access_token=' + config.getToken().access_token,
            });
            $('#admin2Userid').lrformselect({
                layerUrl: config.webportal_server + 'pages/system/user/selectForm.html?access_token=' + config.getToken().access_token,
                layerUrlW: 800,
                layerUrlH: 520,
                dataUrl: config.base_server() + 'users/getName?access_token=' + config.getToken().access_token,
            });
            $('#admin3Userid').lrformselect({
                layerUrl: config.webportal_server + 'pages/system/user/selectForm.html?access_token=' + config.getToken().access_token,
                layerUrlW: 800,
                layerUrlH: 520,
                dataUrl: config.base_server() + 'users/getName?access_token=' + config.getToken().access_token,
            });

            $('#lr_save_btn').on('click', function () {
                if (!$('#form').lrValidform()) {
                    return false;
                }
                var postData = $('#form').lrGetFormData();
                if (postData.admin1Userid == undefined || postData.admin1Userid == "") {
                    learun.alert.warning('请选择设置员！');
                    return;
                }
                if (postData.admin1Userid.indexOf(",") > 0) {
                    learun.alert.warning('仅能配置一个设置员！');
                    return;
                }
                if (postData.admin2Userid == undefined || postData.admin2Userid == "") {
                    learun.alert.warning('请选择审核员！');
                    return;
                }
                if (postData.admin2Userid.indexOf(",") > 0) {
                    learun.alert.warning('仅能配置一个审核员！');
                    return;
                }
                if (postData.admin3Userid == undefined || postData.admin3Userid == "") {
                    learun.alert.warning('请选择审计员！');
                }
                if (postData.admin3Userid.indexOf(",") > 0) {
                    learun.alert.warning('仅能配置一个审计员！');
                    return;
                }
                if (postData.admin1Userid == postData.admin2Userid || postData.admin1Userid == postData.admin3Userid || postData.admin2Userid == postData.admin3Userid) {
                    learun.alert.warning('三个角色不能为同一个人！');
                    return;
                }

                $.lrSaveForm(config.base_server() + 'auth3s/setAdmins?access_token=' + config.getToken().access_token, JSON.stringify(postData), function (res) {
                   // top.layer.alert("设置成功");
                });
            });
        },
        initData: function () {
            $.ajax({
                url: config.base_server() + 'auth3s?access_token=' + config.getToken().access_token,
                type: "get",
                dataType: "json",
                async: false,
                success: function (result) {
                    if (result != null) {
                        $('#form').lrSetFormData(result.data);
                    }
                }
            });
        }
    };

    page.init();
}